{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-05-10T04:27:49.811720Z",
     "start_time": "2025-05-10T04:27:39.101209Z"
    }
   },
   "outputs": [],
   "source": [
    "import time\n",
    "\n",
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "from selenium.webdriver.support.select import Select\n",
    "\n",
    "driver = webdriver.Edge()\n",
    "driver.get(\"https://sahitest.com/demo/selectTest.htm\")\n",
    "\n",
    "driver.maximize_window() # 页面最大化\n",
    "# 定位多选框\n",
    "select = Select(driver.find_element(By.ID,'s1'))\n",
    "# 1.根据option下标选择多选框的内容\n",
    "\"\"\"select.select_by_index(5)\"\"\"\n",
    "\n",
    "# 2.根据option的value值选择多选框内容\n",
    "\"\"\"select.select_by_value(\"47\")\"\"\"\n",
    "\n",
    "# 3.根据下拉框内容的文本信息选择\n",
    "select.select_by_visible_text(\"Fax\")\n",
    "\n",
    "time.sleep(5)\n",
    "driver.close()"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "c41ed5f8b10d73ae"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
